cc.Class({
    extends: cc.Component,
    properties: {
        sharePromptBackground:{
            default:null,
            type:cc.Node
        }
    },
    popSharePrompt(){
        this.node.runAction(cc.sequence(cc.fadeOut(0.5),cc.callFunc(()=>{
            this.node.stopAllActions()
            //this.node.active = false
            this.node.x = cc.view.getVisibleSize().width / 2 + Math.abs(this.node.width) / 2;
            this.node.y = cc.view.getVisibleSize().height / 8;
            this.FlyFlag = false
            this.node.destroy()
        })))
        this.sharePrompt = this.sharePromptBackground.getChildByName('分享面板')
        this.sharePrompt.getComponent('ShareWindow').popOut()
    },
    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},
    start() {

    },
    
    fly() {
        this.FlyFlag = true
        this.sharePrompt = this.sharePromptBackground.getChildByName('分享面板')
        this.period = 3
        this.flyTime = 10
        this.time = 0
        this.node.width = Math.abs(this.node.width)
        this.baseHeight = cc.view.getVisibleSize() / 8;
        if( this.sharePromptBackground.active ==false){
            var size = cc.view.getVisibleSize();
            this.baseHeight = size.height / 8?size.height / 8:this.baseHeight 
            this.node.active = true
            
            this.node.x = cc.view.getVisibleSize().width / 2 + this.node.width / 2;
            this.node.y =this.baseHeight 
            

            var action = cc.sequence(cc.moveTo(this.flyTime/2, cc.v2(-size.width / 2 + this.node.width / 2, this.baseHeight)), cc.callFunc(function () {
                this.node.getComponent('Turn').turn();
            }, this), 
            cc.moveTo(this.flyTime/2, cc.v2(size.width / 2 + this.node.width / 2, this.baseHeight)),
            cc.callFunc(()=>{
                this.node.destroy()
            })
            );
            this.node.runAction(action);
        }else{
            this.node.stopAllActions()
            this.node.active = false
            this.node.x = cc.view.getVisibleSize().width / 2 + this.node.width / 2;
            this.node.y = cc.view.getVisibleSize().height / 8;
        }
    },
    update(dt) {
        if(this.FlyFlag){
            this.time += dt;
            this.node.y = this.baseHeight + Math.sin(this.time * Math.PI * 2 / this.period) * this.node.height / 3.2;
        }
    },
    
});
